/**
 * 
 */
package com.jbat.gwt.tiledmapcreator.client.places;

import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceController;
import com.google.gwt.place.shared.PlaceHistoryHandler;
import com.google.gwt.place.shared.PlaceHistoryMapper;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.web.bindery.event.shared.EventBus;

/**
 * 
 */
public class PlaceHistoryHandlerProvider implements Provider<PlaceHistoryHandler> {
  private final PlaceHistoryMapper placeHistoryMapper;
  private final PlaceController placeController;
  private final EventBus eventBus;

  // set the default place here
  // TODO allow user to select tileset when creating a map
  private final Place defaultPlace = new MapDesignPlace("dungeon&10&10");

  @Inject
  public PlaceHistoryHandlerProvider(PlaceHistoryMapper placeHistoryMapper,
      PlaceController placeController, EventBus eventBus) {
    this.placeHistoryMapper = placeHistoryMapper;
    this.placeController = placeController;
    this.eventBus = eventBus;
  }

  @Override
  public PlaceHistoryHandler get() {
    PlaceHistoryHandler placeHistoryHandler = new PlaceHistoryHandler(placeHistoryMapper);
    placeHistoryHandler.register(placeController, eventBus, defaultPlace);
    return placeHistoryHandler;
  }

}
